package com.bluesky.jwf.component.dialog;

import com.bluesky.jwf.ComponentFactory;
import com.bluesky.jwf.component.Button;
import com.bluesky.jwf.component.Component;
import com.bluesky.jwf.component.Label;
import com.bluesky.jwf.component.event.AbstractEventHandler;
import com.bluesky.jwf.component.event.EventHandler;
import com.bluesky.jwf.component.window.Dialog;
import com.bluesky.jwf.component.window.ModalResult;

public class ConfirmDialog extends Dialog {

	private Label questionLabel;

	private Button buttonYes;
	private Button buttonNo;

	@Override
	public void init(String html) {

		super.init(html);

		setTitle("Confirm Dialog");

		questionLabel = (Label) ComponentFactory.getInstance().createComponent(
				"Label");
		bodyTag.loadByJwfClass("question").replace(questionLabel);

		buttonYes = (Button) ComponentFactory.getInstance().createComponent(
				"Button");
		buttonYes.setText("Yes");
		bodyTag.loadByJwfClass("yes").replace(buttonYes);

		buttonYes.setClickHandler(new AbstractEventHandler() {
			@Override
			public void handle(Component target, Object parameter) {

				modalResult = ModalResult.Yes;

				close();

			}
		});

		buttonNo = (Button) ComponentFactory.getInstance().createComponent(
				"Button");
		buttonNo.setText("No");
		bodyTag.loadByJwfClass("no").replace(buttonNo);
		buttonNo.setClickHandler(new AbstractEventHandler() {
			
			@Override
			public void handle(Component target, Object parameter) {

				modalResult = ModalResult.Cancel;

				close();

			}
		});

	}

	public String getQuestion() {
		return questionLabel.getText();
	}

	public void setQuestion(String question) {
		questionLabel.setText(question);
	}

	public Label getQuestionLabel() {
		return questionLabel;
	}

	public void setQuestionLabel(Label questionLabel) {
		this.questionLabel = questionLabel;
	}

	public Button getButtonOK() {
		return buttonYes;
	}

	public void setButtonOK(Button buttonOK) {
		this.buttonYes = buttonOK;
	}

	public Button getButtonCancel() {
		return buttonNo;
	}

	public void setButtonCancel(Button buttonCancel) {
		this.buttonNo = buttonCancel;
	}
}
